package cave.utils;

public class FloatArray {
	private int numItems, maxItems;
	private float[] array;
	
	public FloatArray() {
		this(10);
	}
	
	public FloatArray(int startSize) {
		array = new float[startSize];
		maxItems = startSize;
	}
	
	public void add(float item) {
		if (numItems >= maxItems) {
			grow(maxItems * 2);
		}
		
		array[numItems++] = item;
	}
	
	public void remove(int index) {
		if (index != numItems - 1) {
			for (int i = index + 1; i < numItems; ++i) {
				array[i-1] = array[i];
			}
		}
		numItems--;
	}
	
	public int size() {
		return numItems;
	}
	
	public float get(int index) {
		return array[index];
	}
	
	public void clear() {
		numItems = 0;
	}
	
	private void grow(int size) {
		float[] newArray = new float[size];
		System.arraycopy(array, 0, newArray, 0, numItems);
		array = newArray;
		maxItems = size;
	}
	
	public float[] getInternalArray() {
		return array;
	}
	
}
